package com.wfm.client;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.concurrent.TimeUnit;

public final class RedisClientUtil {

    static RedissonClient redissonClient;

    static {
        Config config = new Config();
        // 1. Create config object
        config.useSingleServer().
                setAddress("redis://110.40.196.180:6379")
                .setPassword("wfm@1314");

        redissonClient = Redisson.create(config);
    }

    public static String get(String key) {
        return (String) redissonClient.getBucket(key).get();
    }

    public static void set(String key, String value) {
        redissonClient.getBucket(key).set(value);
    }

    public static void set(String key, String value, long time, TimeUnit timeUnit) {
        redissonClient.getBucket(key).set(value, time, timeUnit);
    }

    public static void main(String[] args) {
        set("test", "test");
        System.out.println(get("test"));
    }

}
